<!-- 这是一个聊天的列表项 -->
<template>
  <div class="chat-item" :class="{active:active}">
    <div class="chat-item__avatar">
      <img :src="chatItem.avatar" alt="avatar" />
    </div>
    <div class="chat-item__content">
      <div class="chat-item__content__name"><span>{{ chatItem.name }}</span><span>{{chatItem.school}}</span></div>
      <div class="chat-item__content__message"><span class="message">{{ chatItem.message }}</span><span class="time">{{chatItem.time}}</span></div>
    </div>
  </div>
</template>

<script setup lang="ts">

const props = defineProps({
  chatItem: {
    type: Object,
    required: true,
  },
  active: {
    type: Boolean,
    required: true,
  },
});

</script>

<style scoped>
  .chat-item {
    display: flex;
    align-items: center;
    width: 90%;
    border-radius: 6px;
    padding: 6px 12px;
    background-color: #fff;
    cursor: pointer;
    transition: all 0.3s linear;
    margin: 16px auto;
  }

  .chat-item:hover {
    background-color: #f0f0f0;
    transform: translateY(-2px);
    background-color: rgba(249, 205, 173, .5);
  }

  .chat-item.active {
    background-color: var(--themeColor);
  }

  .chat-item__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px rgb(13, 202, 235) solid;
  }

  .chat-item__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .chat-item__content {
    display: flex;
    flex-direction: column;
    margin-left: 8px;
    width: 70%;
  }

  .chat-item__content__name {
    display: flex;
    justify-content: space-between;
    font-size: var(--font-16);
    margin-bottom: 5px;
  }

  .chat-item__content__message {
    display: flex;
    flex-direction: column;

    font-size: var(--font-12);
    width: 100%;
    color: #666;
  }

  .chat-item__content__message .message {
    /* 首行缩进 */
    text-indent: 2em;
    width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
</style>